#ifndef DYNAMIC_SIMULATOR_H
#define DYNAMIC_SIMULATOR_H

#include "ElementContainer.h"
#include "VolumetricMeshLoader.h"
#include "Integrator.h"

#define DENSITY	1

class DynamicSimulator
{
public:
	DynamicSimulator(void);
	~DynamicSimulator(void);
	void LoadVolumetricMesh(char* name);
	void InitElement(float E = 2300000.3, float mu = 0.33);
	void InitKe();
	void InitMe();
	void InitPinv();
	void CalRe();
	void AssemblyK();
	void Update( float dt );
	void ForwardEuler();
	void BackwardEuler();
	mat3f PolarDecomposition(mat3f B);
	mat3f QRDecomposition(mat3f B);
	void CalDeterminant(float& a, float& b, float& c, float& d, Vertex* va, Vertex* vb, Vertex* vc);

	// For test only
	void CalForce();
	void Perturb();

	ElementContainer* simplex;
	VolumetricMeshLoader loader;
	Integrator* solver;

	float E;		// Young's modulus
	float mu;		// Poisson's ratio
	float timestep;
	float** K;
	float* f0;
	float* xi;
	float* f;
};

#endif

